// Cookies 的使用方法
// 如何从Cookies 里拿token 和修改token 和删除 token 

import Cookies from 'js-cookie';

const TokenKey = 'Hsbank';

export function getToken() {
    const cookies = Cookies.get(TokenKey);
    if (cookies === 'undefined' || cookies === undefined) { return '' }
    // console.log('cookies', cookies);

    return cookies;
}
// 获取银行号 getTokenValue getTokenHsbankNo
export function getTokenHsbankNo(value: any) {
    const cookies = Cookies.get(value);
    if (cookies === 'undefined' || cookies === undefined) { return '' }
    // console.log('cookies', cookies);

    return cookies;
}

export function setToken(token: any) {
    return Cookies.set(TokenKey, token);
}

export function setTokenToName(token: any) {
    let tokenValue = JSON.parse(token)
    return Cookies.set('HsbankNo', tokenValue.lesseeCode);
}


export function removeToken() {
    return Cookies.remove(TokenKey);

}

export function removeTokenToname() {
    return Cookies.remove('HsbankNo');
}

class LocalCache {
    setCache(key: string, value: string) {
        window.localStorage.setItem(key, JSON.stringify(value))
    }
    getCache(key: string) {
        const cacheVal = window.localStorage.getItem(key)
        if (cacheVal) {
            return JSON.parse(cacheVal)
        }
    }
    deleteCache(key: string) {
        window.localStorage.removeItem(key)
    }
    clearCache() {
        window.localStorage.clear()
    }
}

export default new LocalCache